package com.qf.dao.DaoImpl;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.util.DBUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package com.qf.dao.DaoImpl
 * @Description:
 * @Date 2022/5/27 19:32
 */
public class UserDaoImpl implements UserDao {
    private QueryRunner qr = new QueryRunner(DBUtil.getDateSource());
    @Override
    public User selectUser(String username) {
        String sql = "select * from User where username =? ";
        try {
            return qr.query(sql, new BeanHandler<User>(User.class), username);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int inserteUser(User user) {
        String sql = "insert into user  (username,password,state) values (?,?,?)";
        try {
            return qr.update(sql,user.getUsername(),user.getPassword(),user.getState());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
